var util=require('../../../utils/util.js');
Page({

  /**
   * 页面的初始数据
   */
  data: {

    state: true,
    date:{sdate:'',edate:''},
    stime:'08:00',
    etime:'23:00',
    advanceTime:10,
   // shop: shop
  },
  onLoad:function(){
    this.init();
    this.getShop();
  },
  init:function(){
    var date=new Date();
    var sdate=date.getFullYear()+"-"+(date.getMonth()+1)+"-"+date.getDate();
    this.setData({
      date: { sdate: sdate, edate: sdate}
    })
  },
  getShop:function(){
    var that=this;
    util.fetchGet(
      util.url.shop_shop_getshop,
      function (ret) {
        var myshop = ret.data;
        var sevicetime = myshop.servicetime;
        if (sevicetime){
          var time = sevicetime[0].split('-');
          that.setData({
            stime: time[0],
            etime: time[1] 
          })
        }
        
        var holidays=myshop.holiday
        if (holidays){
          var holiday = holidays[0].split(' ');
          var date = { sdate: holiday[0], edate: holiday[1] }
          that.setData({ date: date})
        }
       
        that.setData({ 
          state: myshop.state==0?true:false,         
          advanceTime: myshop.advanceTime
        })
      }
    )
  },
  bindDateChange:function(e){
    var id=e.currentTarget.dataset.id;
    var date =this.data.date;
    date[id]=e.detail.value;
    this.setData({
      date: date
    })
  },
  bindTimeChange1: function (e) {
    this.setData({
      stime: e.detail.value
    })
  },
  bindTimeChange2: function (e) {
    this.setData({
      etime: e.detail.value
    })
  },
  bindShopState:function(){
    var state = this.data.state;
    this.setData({
      state: state?false:true
    })
  },
  bindAdvanceTime:function(e){
    this.setData({ advanceTime:e.detail.value})
  },
 bindsubmit: function () { 
    var that = this;
    var shop={};
    shop.state=this.data.state?0:1;
    shop.advanceTime=this.data.advanceTime;
    shop.servicetime=[this.data.stime + '-' + this.data.etime],
    shop.holiday = [this.data.date.sdate + ' ' + this.data.date.edate],
    util.fetchPost(
      util.url.shop_shop_setshop,
      shop,
      function (ret) {
        console.log(ret);
        wx.navigateBack({})
      }
    )
  },

})